package com.neko.Thread_Learning;

import java.text.SimpleDateFormat;
import java.util.Date;

// 模拟【倒计时】
public class t10_2_Thread_sleep {

    public static void main(String[] args) {
        try {
            printTime();
//            tenDown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 模拟【倒计时】
    public static void tenDown() throws InterruptedException {

        int num = 10;

        while (true) {
            Thread.sleep(1000);
            System.out.println(num--);

            if (num <= 0) {
                break;
            }
        }
    }

    // 打印当前系统时间
    public static void printTime() throws InterruptedException {

        Date date = new Date(System.currentTimeMillis());

        while (true) {
            try {
                Thread.sleep(1000);
                System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
                date = new Date(System.currentTimeMillis()); // 更新当前时间

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
